<template>
	<h3>OA登录</h3>
	<el-form
	    :label-position="labelPosition"
	    label-width="100px"
	    :model="user"
	    style="max-width: 350px;margin: 0px auto;"
	>
	<el-form-item label="账号">
		<el-input v-model="user.accountNum" placeholder="请输入登录的账号"></el-input>
	</el-form-item>
	<el-form-item label="密码">
		<el-input type="password" v-model="user.password" placeholder="请输入登录的密码"></el-input>
	</el-form-item>
		<el-button @click="submit">确定</el-button><el-button @click="cancel">取消</el-button>
			
	</el-form>
</template>

<script>
	import qs from 'qs'
	import { ElMessage } from 'element-plus'
	export default {
	    data(){
			return{
				user:{}
			}
		},
		methods:{
			submit(){
				let that=this
				let str=qs.stringify(that.user)
				
				that.$axios.get("http://localhost:8080/user/login?"+str).then(function(res){
					if(res.data!=null&&res.data!='')
					{
						//将登录成功的用户信息，共享到vuex中
						that.$store.commit('user',res.data)
						//将登录成功的用户信息，保存到sessionStorage   
						sessionStorage.setItem("user",JSON.stringify(res.data))
						
						that.$router.push("/Index")  //验证成功，路由跳转到系统主页面
					}else{
						 ElMessage.error('登录失败，请重新登录')
					}
				})
			},
			cancel(){
				this.user.accountNum=null
				this.user.password=null
			}
		}
	}
</script>

<style>
</style>
